package com.etone.smartAudit.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: sovy
 * @date: 2019-06-23 18:16:28
 * @description: 任务类型
 */
public enum TaskType {
    MODULE(10, "模型任务"),
    WORK(20, "工作任务"),
    WORK_TOOL(2010, "工具中台任务"),
    WORK_SERVICE(2011, "服务支撑中台任务"),
    WORK_ITEM_SOURCE(2012, "资源调度中台任务"),
    WORK_DATA(2013, "数据中台任务"),
    NEW_DATA_APPLY(2100, "新数据申请"),
    MAN_MADE_STORAGE(2200, "人工入库"),
    TEMPORARY(30, "临时任务"),
    SUPER_WORK(3010, "超级本"),
    WORK_STATION(3011, "工作站"),
    ITEM(40, "项目任务"),
    ITEM_RISK(4010, "审计风险"),
    ITEM_ITEM(4011, "项目任务"),
    ITEM_ITEM_SOURCE(401110, "项目资源任务"),
    DATA_MODEL_AUTH(41, "数据模型授权"),
    RESOURCE(42, "资源任务"),
    RESOURCE_APPLY(4201, "资源申请"),
    RESOURCE_EXPANSION(4202, "资源扩容"),
    RESOURCE_DEVICE(4300, "设备租赁任务"),
    ;

    @Getter
    private Integer value;

    @Getter
    private String remark;

    TaskType(int value, String remark) {
        this.value = value;
        this.remark = remark;
    }

    /**
     * 临时资源管理任务
     *
     * @return
     */
    public static List<TaskType> temporaryTask() {
        return Arrays.asList(TaskType.values()).stream().filter(taskType ->
                taskType.value.toString().startsWith(TaskType.TEMPORARY.value.toString())
        ).collect(Collectors.toList());
    }

    public static Boolean isTemporaryTask(TaskType taskType) {
        return taskType != null && temporaryTask().contains(taskType);
    }

    /**
     * 获取项目任务
     *
     * @return
     */
    public static List<TaskType> workTask() {
        return Arrays.asList(TaskType.values()).stream().filter(taskType ->
                taskType.value.toString().startsWith(TaskType.WORK.value.toString())
        ).collect(Collectors.toList());
    }

    /**
     * 获取资源任务
     *
     * @return
     */
    public static List<TaskType> resourceTask() {
        return Arrays.asList(TaskType.values()).stream().filter(taskType ->
                taskType.value.toString().startsWith(TaskType.RESOURCE.value.toString())
        ).collect(Collectors.toList());
    }

    /**
     * 判断是否是工作任务
     *
     * @param taskType
     * @return
     */
    public static Boolean isWorkTask(TaskType taskType) {
        return taskType != null && workTask().contains(taskType);
    }

    /**
     * 获取项目任务
     *
     * @return
     */
    public static List<TaskType> itemTask() {
        return Arrays.asList(TaskType.values()).stream().filter(taskType ->
                taskType.value.toString().startsWith(TaskType.ITEM.value.toString())
        ).collect(Collectors.toList());
    }

    /**
     * 判断是否是项目任务
     *
     * @param taskType
     * @return
     */
    public static Boolean isItemTask(TaskType taskType) {
        return taskType != null && itemTask().contains(taskType);
    }

    /**
     * 判断是否是资源申请或者资源扩容任务
     *
     * @return
     */
    public static Boolean isResourceTask(TaskType taskType) {
        return taskType != null && resourceTask().contains(taskType);
    }

    /**
     * 任务状态：执行中（EXECUTE_STARTING）下一步状态是审核通过（PASS）
     *
     * @param taskType
     * @return
     */
    public static Boolean getExecute_starting2PassTask(TaskType taskType) {
        return Arrays.asList(RESOURCE_APPLY, RESOURCE_EXPANSION, NEW_DATA_APPLY, MAN_MADE_STORAGE, WORK_TOOL).contains(taskType);
    }
}
